/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> res;
        deque<TreeNode*> deq;
        if(root == nullptr) 
            return res;
        else
            deq.push_back(root);

        while(!deq.empty())
        {
            TreeNode* deqFront = deq.front();
            cout<<deqFront->val<<" ";
            deq.pop_front();
            if(deqFront->left!=nullptr)
                deq.push_back(deqFront->left);
            if(deqFront->right!=nullptr)
                deq.push_back(deqFront->right);
        }

        return res;
    }
};